<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 边界符 ^ &
        var rg = /abc/ //正则表达式里面不需要加引号 无论是字符型还是数字型
        // 未加边界符的模糊匹配 只要包含abc截为true
        console.log(rg.test('abc'));//true
        console.log(rg.test('abcd'));//true
        console.log(rg.test('aabcd'));//true
        console.log(rg.test('abc123'));//true
        console.log(rg.test('123abc'));//true
        console.log(rg.test('1abc23'));//true
        console.log('----------------');
        
        var rg1 = /^abc/
        // 精确匹配 必须以abc开头才符合要求
        console.log(rg1.test('abc'));//true
        console.log(rg1.test('abcd'));//true
        console.log(rg1.test('aabcd'));//false
        console.log(rg1.test('abc123'));//true
        console.log(rg1.test('123abc'));//false
        console.log(rg1.test('1abc23'));//false 
        console.log('----------------');
        var rg2 = /^abc$/
        // 精确匹配 内容必须是abc才符合要求
        console.log(rg2.test('abc'));//true
        console.log(rg2.test('abcd'));//false
        console.log(rg2.test('aabcd'));//false
        console.log(rg2.test('abc123'));//false
        console.log(rg2.test('123abc'));//false
        console.log(rg2.test('1abc23'));//false 

    </script>
</body>

</html>